<?php
namespace app\yunda\model;

use think\Model;
use traits\model\SoftDelete;

/**
 * 单号表
 * @package app\yunda\model
 */
class Danhao extends Model
{
    use SoftDelete;
    protected $table = 'dp_yd_danhao';
    protected $autoWriteTimestamp = true;

    //获取一条可使用的单号
    public static function getDanHao()
    {
        $res=self::where(['is_use'=>0])->find();
        if(empty($res)) return $res['order_sn']='暂无可用运单号';
        return $res['order_sn'];
    }

    //修改单号的使用状态
    public static function changeStatus($order_sn='')
    {
        if (empty($order_sn)) return mogo_error('参数错误',404);
        $row=self::get(['order_sn'=>$order_sn]);
        if(empty($row))return mogo_error('运单号不存在',404);
        $row=self::update(['id'=>$row['id'],'is_use'=>1]);
        return $row;
    }
}
